/*
@title: Countdown Golf
@description: Countdown Golf is a puzzle game inspired by Herugolf where players must hit balls into holes without crossing paths. Each ball displays a number indicating how far it can be hit, decreasing with each move, while navigating around water hazards. With 360 unique courses to solve, players can aim for perfect par scores by using strategic moves and undo options.
@author: schoblaska
@tags: ['puzzle']
@addedOn: 2024-03-30

Countdown Golf is based on Herugolf
(https://www.nikoli.co.jp/en/puzzles/herugolf/) by NIKOLI.

Hit each ball into a hole without crossing any other ball's path. Each ball is
labeled with a number; that number indicates how far the ball will travel, and
decreases by one each time the ball is hit. Balls can cross blue water hazard
tiles but not land on them. You can hit a ball backwards to undo but a stroke
will be added to your score.

Use WASD to move the cursor and J to select. Once a ball is selected, choose a
direction to hit it in with WASD.

Countdown Golf has 360 original courses. Each course has only one solution. In
higher-numbered courses you can score under par with perfect play.

https://countdown.golf
*/

const six = "6";
const five = "5";
const four = "4";
const three = "3";
const two = "2";
const one = "1";
const blank = "b";
const hole = "h";
const holeWon = "H";

const upIn = "u";
const downIn = "d";
const leftIn = "l";
const rightIn = "r";
const upOut = "U";
const downOut = "D";
const leftOut = "L";
const rightOut = "R";

const cursor = "s";
const valid = "v";
const invalid = "i";
const grass = "g";
const water = "w";

// for info screen
const infoWater = "W";
const infoGrass = "X";
const infoSky = "Y";
const infoCloud = "Z";
const infoFlagNE = "7";
const infoFlagSE = "8";
const infoFlagSW = "9";
const infoFlagNW = "0";

const numberTypes = [one, two, three, four, five, six];
const inArrowTypes = [upIn, downIn, rightIn, leftIn];
const outArrowTypes = [upOut, downOut, rightOut, leftOut];
const arrowTypes = inArrowTypes.concat(outArrowTypes);
const selectableTypes = numberTypes.concat([holeWon]);
const impassableTypes = numberTypes.concat([hole, holeWon]).concat(arrowTypes);
const unlandableTypes = numberTypes.concat(holeWon, water).concat(arrowTypes);

let courseNumber = 0;
let loadedCourses = [];
let selected = false;
let screen = "gameTitle";
let wonOnce = false;

const gameSelectOptions = ["18 courses", "front 9", "back 9", "endless"];
let gameSelect = 0;

// store the value of the ball that is sunk in each hole, for undo
let holeVals = {};

setLegend(
	[
		six,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02000220...
....0020222200..
....0220002210..
....02202022L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		five,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02000220...
....0020222200..
....0220002210..
....02222022L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		four,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02020220...
....0020202200..
....0220002210..
....02222022L0..
....0022202100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		three,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02000220...
....0022202200..
....0220002210..
....02222022L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		two,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02000220...
....0022202200..
....0220002210..
....02202222L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		one,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02002220...
....0022022200..
....0222022210..
....02220222L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		blank,
		bitmap`
................
................
................
................
......000000....
.....00222200...
.....02000220...
....0020002200..
....0220002210..
....02200022L0..
....0020002100..
.....022222L0L..
.....00221L00L..
......000000L...
................
................`,
	],
	[
		hole,
		bitmap`
.......331......
.....33331......
...3333331......
.....33331......
.......331......
........11......
........11......
.....00011000...
....0000110000..
....0000000000..
.....00000000...
................
................
................
................
................`,
	],
	[
		holeWon,
		bitmap`
.......221......
.....22221......
...2222221......
.....22221......
.......221......
........11......
........11......
.....00011000...
....0000110000..
....0000000000..
.....00000000...
................
................
................
................
................`,
	],
	[
		upIn,
		bitmap`
................
........00......
........00......
........00......
........00......
........00......
........00......
........00......
.......0000.....
.......0000.....
........00......
................
................
................
................
................`,
	],
	[
		downIn,
		bitmap`
................
................
................
................
................
................
................
........00......
.......0000.....
.......0000.....
........00......
........00......
........00......
........00......
........00......
........00......`,
	],
	[
		leftIn,
		bitmap`
................
................
................
................
................
................
................
........00......
.0000000000.....
.0000000000.....
........00......
................
................
................
................
................`,
	],
	[
		rightIn,
		bitmap`
................
................
................
................
................
................
................
........00......
.......000000000
.......000000000
........00......
................
................
................
................
................`,
	],
	[
		upOut,
		bitmap`
................
........00......
........00......
........00......
........00......
........00......
........00......
........00......
.......0000.....
.......0000.....
........00......
................
................
................
................
................`,
	],
	[
		downOut,
		bitmap`
................
................
................
................
................
................
................
........00......
.......0000.....
.......0000.....
........00......
........00......
........00......
........00......
........00......
........00......`,
	],
	[
		leftOut,
		bitmap`
................
................
................
................
................
................
................
........00......
.0000000000.....
.0000000000.....
........00......
................
................
................
................
................`,
	],
	[
		rightOut,
		bitmap`
................
................
................
................
................
................
................
........00......
.......000000000
.......000000000
........00......
................
................
................
................
................`,
	],
	[
		cursor,
		bitmap`
................
................
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..6666666666666.
..666666666666..
..66666666666...
................`,
	],
	[
		valid,
		bitmap`
................
................
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..4444444444444.
..444444444444..
..44444444444...
................`,
	],
	[
		invalid,
		bitmap`
................
................
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..3333333333333.
..333333333333..
..33333333333...
................`,
	],
	[
		grass,
		bitmap`
DD44444444444444
DDDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDDD
4DDDDDDDDDDDDDD4
4DDDDDDDDDDDDD44`,
	],
	[
		water,
		bitmap`
5577777777777777
5555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555555
7555555555555557
7555555555555577`,
	],
	[
		infoWater,
		bitmap`
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555`,
	],
	[
		infoGrass,
		bitmap`
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD
DDDDDDDDDDDDDDDD`,
	],
	[
		infoSky,
		bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777`,
	],
	[
		infoCloud,
		bitmap`
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222`,
	],
	[
		infoFlagNE,
		bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777
L777777777777777`,
	],
	[
		infoFlagSE,
		bitmap`
L444444444444444
L444444444444444
L444444444444444
L444444444444444
L444444444444444
L444444444444444
L000444444444444
L000044444444444
0000044444444444
0000444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444`,
	],
	[
		infoFlagSW,
		bitmap`
444444444444444L
444444444444444L
444444444444444L
444444444444444L
444444444444444L
444444444444444L
444444444444000L
444444444440000L
4444444444400000
4444444444440000
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444`,
	],
	[
		infoFlagNW,
		bitmap`
7777777777777777
7777777777777777
7777777777777777
777777777777777L
7777777777773333
7777777777773333
7777777733333333
7777777733333333
7777333333333333
7777333333333333
7777777733333333
7777777733333333
7777777777773333
7777777777773333
777777777777777L
777777777777777L`,
	]
);

const courseGroups = [
	[
		[
			map`
.2...3
...h..
.....w
.hh.w.
3.....`,
			8,
			8,
		],
		[
			map`
....w.
..h..3
....h.
..ww3.
4wh...`,
			10,
			10,
		],
		[
			map`
5.....
w2h...
2..w..
.h..w.
.h....`,
			8,
			8,
		],
		[
			map`
.....5
.2.hhw
.....w
..h...
....2.`,
			9,
			9,
		],
		[
			map`
.....4
.hh.w.
......
.2.h.w
4.....`,
			9,
			9,
		],
		[
			map`
...2w4
..2...
h.w...
hw.hww
......`,
			8,
			8,
		],
		[
			map`
....2.
..h.w.
......
.2.hhw
.w...5`,
			9,
			9,
		],
		[
			map`
h....h
....h.
w.ww.w
2.3...
5..ww.`,
			7,
			7,
		],
		[
			map`
.h...4
..w...
2w.h..
.w..3w
.h....`,
			9,
			9,
		],
		[
			map`
..2...
....hw
w.hw..
.hw.w4
....4.`,
			7,
			7,
		],
		[
			map`
.w.h.2
wwh...
..whww
....4.
.4.w..`,
			9,
			9,
		],
		[
			map`
......
h..h..
.....w
.wh.2.
...3w4`,
			9,
			9,
		],
		[
			map`
......
h.....
..hhw.
w2....
4.w..4`,
			10,
			10,
		],
		[
			map`
w23...
......
..hw..
.hww.h
4.....`,
			9,
			9,
		],
		[
			map`
h..w..
w.w.hw
.2..w.
.wh2w.
5.....`,
			9,
			9,
		],
		[
			map`
.h3w..
...w..
2.h...
.....h
4....w`,
			9,
			9,
		],
		[
			map`
.ww3w.
.....h
...h..
h...2.
w....4`,
			9,
			9,
		],
		[
			map`
wh..2h
......
ww.h..
..3w..
w3w...`,
			8,
			8,
		],
		[
			map`
h.....
..ww4.
.wh.w.
.wh...
...2.4`,
			9,
			9,
		],
		[
			map`
4w3.w.
.w.h..
....2.
.w...h
.....h`,
			9,
			9,
		],
	],
	[
		[
			map`
3.....
2.3..h
.....2
...hhw
h.....`,
			10,
			10,
		],
		[
			map`
h....h
ww3...
..w...
....h3
44.w.h`,
			9,
			9,
		],
		[
			map`
.h2.4h
.h..w.
2.....
..h..2
...w.w`,
			10,
			10,
		],
		[
			map`
4.....
.h..w.
...2w.
w.hw.w
h2..h4`,
			9,
			9,
		],
		[
			map`
.h.w..
.2w.h.
2.....
..h...
.h..24`,
			10,
			10,
		],
		[
			map`
2.....
h.h..3
...w3.
...hw.
2.h...`,
			10,
			10,
		],
		[
			map`
.ww3w.
..h...
...hhw
h22...
.4....`,
			11,
			11,
		],
		[
			map`
4h..2.
w.hw..
w....h
.2..ww
hw...3`,
			8,
			8,
		],
		[
			map`
..h...
2..hw.
....3.
....w3
hh...4`,
			9,
			9,
		],
		[
			map`
...32.
..h..w
w..w.h
3.w.w.
.h2..h`,
			10,
			10,
		],
		[
			map`
h.3...
......
..hhh.
2...2w
.....4`,
			11,
			11,
		],
		[
			map`
2.3...
.h..w.
...2..
h....h
.2.wh.`,
			9,
			9,
		],
		[
			map`
442..h
..3.w.
...h.w
..w...
h....h`,
			10,
			10,
		],
		[
			map`
3.w.w.
...h.h
.3...w
..w2..
3h...h`,
			11,
			11,
		],
		[
			map`
.w.3h.
..w.3.
.w.h.2
hwhw.w
.3....`,
			11,
			11,
		],
		[
			map`
2...hw
..h..h
3.....
w3....
h.ww4w`,
			9,
			9,
		],
		[
			map`
h..w..
h.w2w.
.2.w.w
2.h.h.
5.....`,
			10,
			10,
		],
		[
			map`
..h.3.
.....h
.wh2..
......
3.h..2`,
			10,
			10,
		],
		[
			map`
....hh
..h...
.....2
.2.h2w
.....5`,
			10,
			10,
		],
		[
			map`
.4....
2h....
....hw
....w.
h33h..`,
			10,
			10,
		],
	],
	[
		[
			map`
4...3h
..2.w.
w...2w
.h...w
h.h3.h`,
			11,
			11,
		],
		[
			map`
w2..2.
2..h..
h.hw.h
..wwh.
.22...`,
			10,
			10,
		],
		[
			map`
...3.w
..hww3
..2...
h2hhhw
2.....`,
			12,
			12,
		],
		[
			map`
5ww.wh
....w.
.hhhww
...2h.
3w2..3`,
			11,
			11,
		],
		[
			map`
h.w.w5
2w.2..
.2w..h
.hwh..
wwh..2`,
			9,
			9,
		],
		[
			map`
..hwh.
h..h..
.2....
..2.2.
2.h2w.`,
			10,
			10,
		],
		[
			map`
.w..w3
.h..2.
w2....
..2h.h
4.hwh.`,
			11,
			11,
		],
		[
			map`
2..2w.
..hw2.
.2...w
h.wh.h
h....3`,
			11,
			11,
		],
		[
			map`
...3.2
..hw..
.2..h.
h..hww
h.2..2`,
			11,
			11,
		],
		[
			map`
h....3
2..h..
w2...2
.hh..2
ww.hw.`,
			11,
			11,
		],
		[
			map`
hww.4.
3w..2w
..h..2
w.hh.h
...2..`,
			10,
			10,
		],
		[
			map`
.w..w.
.2h.2h
w.....
...h..
4h2wh2`,
			12,
			12,
		],
		[
			map`
4w32w3
.w....
.2..h.
.w...h
h.h.h.`,
			9,
			9,
		],
		[
			map`
...hh.
ww2w..
.2ww.2
3..2w.
h.hwwh`,
			11,
			11,
		],
		[
			map`
......
h.h..3
..2...
.h.2.w
3..h4h`,
			10,
			10,
		],
		[
			map`
....2.
..hh..
2..w.h
.3.2..
.h2w.h`,
			11,
			11,
		],
		[
			map`
h.h.ww
...ww3
.2.h2w
2.....
..h2.h`,
			10,
			10,
		],
		[
			map`
.2..hh
2..23.
.h...w
..h.w2
h.....`,
			11,
			11,
		],
		[
			map`
h..2.h
..2.w.
h..2w.
wh3w..
3....h`,
			11,
			11,
		],
		[
			map`
.....2
wh2.h.
.h.w..
.h.3wh
23.w..`,
			12,
			12,
		],
	],
	[
		[
			map`
h.53wh.
ww..w..
2.ww...
.......
.w..whw
h3.w...`,
			13,
			13,
		],
		[
			map`
.2.3.w.
.......
2......
.h..w.h
.w.w.hw
h.4w.w.`,
			11,
			11,
		],
		[
			map`
....h..
..3....
.h..3.w
..w....
.wh..h.
52.....`,
			10,
			10,
		],
		[
			map`
......h
..3h...
.......
.3whhw2
ww.....
w4.ww..`,
			12,
			12,
		],
		[
			map`
6ww..wh
2w2....
..ww.w.
.h...w.
wwhh...
w5...w.`,
			10,
			10,
		],
		[
			map`
...3...
.....5.
w3...2.
..h..wh
ww.....
..w.hhw`,
			13,
			13,
		],
		[
			map`
h.....3
3.....4
.....h.
.......
..whww.
..3.w.h`,
			10,
			10,
		],
		[
			map`
5w4....
.....4.
.....2.
..hhw..
.....h.
.w...h.`,
			14,
			14,
		],
		[
			map`
55.....
..w....
...h...
w...h.w
.....3.
h....h3`,
			9,
			9,
		],
		[
			map`
6...w..
.4..w.w
h..hh..
.w.....
w...w3.
3.w...h`,
			10,
			10,
		],
		[
			map`
h.4....
..w.h.w
....w2.
...h...
.3..h..
....w.6`,
			11,
			11,
		],
		[
			map`
...w..h
.....ww
.w...2.
.h.....
.wh...4
5.ww3hw`,
			10,
			10,
		],
		[
			map`
5....h2
.h3w..w
w..w...
...3..h
wwh...w
..ww.ww`,
			11,
			11,
		],
		[
			map`
.w...3.
.h....w
2..h...
.wh.w..
....33.
h..w.w.`,
			11,
			11,
		],
		[
			map`
h...ww.
4h....w
...w...
.w.2...
w..w3h4
......h`,
			13,
			13,
		],
		[
			map`
h......
4.www..
.2.2w.w
.....hw
.w..hh.
..w.w.5`,
			13,
			13,
		],
		[
			map`
..h..w4
4....3.
.2.h...
.....w.
..hww.h
..w...w`,
			10,
			10,
		],
		[
			map`
.w....4
..w...3
.w.w..2
.w..h..
h..h.hw
3.w.w.w`,
			12,
			12,
		],
		[
			map`
h..wwww
w.w...5
...hh..
w.....2
.w2..w.
5....h.`,
			10,
			10,
		],
		[
			map`
.w4....
4w...2w
...h.h.
.w..w..
.3.w.h.
......h`,
			12,
			12,
		],
	],
	[
		[
			map`
h......
.h.ww.w
w..h3.w
.......
4..2wh4
..4...h`,
			12,
			12,
		],
		[
			map`
w..w.hw
...w..h
..h.w..
whw..2w
3.w.4.2
6....wh`,
			12,
			12,
		],
		[
			map`
h..2ww.
.w.....
h.2..w3
.2w.hw.
.w.h..w
5.....h`,
			12,
			12,
		],
		[
			map`
hw...5h
.......
..w.3h.
...3.w.
w.3.wh.
4h.w...`,
			12,
			12,
		],
		[
			map`
h..2ww3
...ww5w
.2.h2ww
.....w.
..h....
....hh.`,
			14,
			14,
		],
		[
			map`
hww.w5.
..h3...
...2...
....3h.
......h
3.h..w.`,
			12,
			12,
		],
		[
			map`
.2..hh.
3.....w
4....w3
...3...
.wh.w.w
.h...wh`,
			13,
			13,
		],
		[
			map`
.h....2
..ww.2.
.w2.w..
.w....h
...hhh.
3.....5`,
			14,
			14,
		],
		[
			map`
h.h...h
.....3.
w...h.w
2......
wwh.w2.
.....45`,
			12,
			12,
		],
		[
			map`
..w.wwh
h......
..2...3
......h
w......
44hh.2.`,
			12,
			12,
		],
		[
			map`
2h.....
...2...
......2
h2h.h..
5......
ww....h`,
			13,
			13,
		],
		[
			map`
wwwhwh3
....h..
..h..2.
...2.w.
33.....
.w.w.h.`,
			12,
			12,
		],
		[
			map`
.h.3.wh
...3...
....3..
....2..
..hww.h
3hw..ww`,
			12,
			12,
		],
		[
			map`
.....w3
whw...3
w.2.h.h
.ww...w
w..h.2.
.wh.2w.`,
			12,
			12,
		],
		[
			map`
w4.....
h.w...w
..3hw..
..w.w..
2h...ww
h..24.h`,
			14,
			14,
		],
		[
			map`
....4..
..4.w.h
.3.....
...22.h
..hw.ww
w.wh.h.`,
			11,
			11,
		],
		[
			map`
.w.h...
....4..
.h2w.h.
...hww3
...h..w
4.w..3.`,
			13,
			13,
		],
		[
			map`
w.4...h
.......
...w.h.
....w.3
.h2..hw
45w...h`,
			11,
			11,
		],
		[
			map`
w.hw.w4
.hw...5
...3.w.
.2..hw.
...h...
h.4.w..`,
			11,
			11,
		],
		[
			map`
...w..h
.whh4.h
.h.....
3.....w
...2..2
w....3w`,
			14,
			14,
		],
	],
	[
		[
			map`
.hwwww5
.....22
2..2...
...w...
..h.hhh
h.....5`,
			14,
			14,
		],
		[
			map`
.h.w..5
...32..
.....2h
..wh..2
hwwwhwh
.3.w...`,
			13,
			13,
		],
		[
			map`
...3.w.
......3
hh....2
w.h....
2w.h...
h..23wh`,
			14,
			14,
		],
		[
			map`
.h....h
.3..4h.
2.2..w.
...3w..
.......
h.whh.3`,
			13,
			13,
		],
		[
			map`
h3...h.
.hw3...
..2...2
w...h.w
.2.....
5.h.wh.`,
			13,
			13,
		],
		[
			map`
2.3..2h
.hwh.4.
.......
h..w..w
h2w.h..
......5`,
			14,
			14,
		],
		[
			map`
h....h.
w..ww.2
...h.2w
.w3....
43....h
wh.w3h.`,
			12,
			12,
		],
		[
			map`
h.h.w23
...hw.w
.....3.
2w...h.
w..hw..
.3w.2h.`,
			15,
			15,
		],
		[
			map`
.5w...h
.h..2..
h..w.wh
..whhw.
w2..w2w
2..w..4`,
			13,
			13,
		],
		[
			map`
2w.h.2h
....2..
..hw...
.w...h.
...hh.4
4.....4`,
			13,
			13,
		],
		[
			map`
6...wwh
...2...
hh....h
.....h.
..3h3..
w..w3.2`,
			14,
			14,
		],
		[
			map`
.ww.4w.
.h22w.h
...3...
...hww.
.2h....
.h..2.h`,
			15,
			15,
		],
		[
			map`
h2...w.
w....3w
w..h...
.h..2..
w....hw
5h.2.h5`,
			13,
			13,
		],
		[
			map`
hh..2w.
..h2...
.2..h..
2...hw.
...ww33
.hw...w`,
			14,
			14,
		],
		[
			map`
..h.22h
h.wh...
.......
w...hhw
...2...
4...w43`,
			13,
			13,
		],
		[
			map`
34h.w.4
....w.w
...2..2
.w.....
whh.w..
.hwh.4h`,
			13,
			13,
		],
		[
			map`
www.w.3
.h..2h.
..h..3.
...3.w.
.2..h..
.w2w.hh`,
			12,
			12,
		],
		[
			map`
..h..h.
3.2.h.4
w..h...
.w...2.
h.hw2..
.3w..w.`,
			14,
			14,
		],
		[
			map`
5.2w.ww
...2h.w
.h...h2
.hh....
...2..h
.....3w`,
			13,
			13,
		],
		[
			map`
32....h
..h4w4.
..h....
....3.2
..h.w..
h.w..hw`,
			13,
			13,
		],
	],
	[
		[
			map`
.hhw...5
.h....w6
.w.....4
w23w....
..w.....
......hw
wh...ww.`,
			11,
			11,
		],
		[
			map`
.h.....6
4w.ww.4w
......w.
..w.hww.
......2.
.......w
3w.h.h.h`,
			12,
			12,
		],
		[
			map`
.....2.h
w.....w.
w..2w.h.
.h...w..
..ww..h.
...w..6.
w..3w.h6`,
			12,
			12,
		],
		[
			map`
3wwhw.3.
.6......
.3ww.w..
......h.
.h..2...
......h.
h.w..w..`,
			15,
			15,
		],
		[
			map`
.ww.w.6.
.w3.w...
.2.....h
.w.hwwh.
w....2..
......wh
6ww.w.hw`,
			14,
			14,
		],
		[
			map`
..w..h.h
4...h..2
w..w....
hw3.....
.......h
..4.....
.w...w.4`,
			14,
			14,
		],
		[
			map`
3.....hw
ww....4.
..wh.2..
....3..w
...w...w
h.w2.hw.
.h...w..`,
			14,
			14,
		],
		[
			map`
.h...w..
..w.h...
.h..wwww
....w2w.
..h3..w4
....4...
...w4h..`,
			14,
			14,
		],
		[
			map`
2..3...w
..3.w...
.3..4...
h.....hh
........
.h.w..w.
...h....`,
			13,
			13,
		],
		[
			map`
4.......
.h...w..
.hh...h.
......ww
ww.w3...
.......2
3..3wh..`,
			15,
			15,
		],
		[
			map`
........
..h.h.ww
.4..3w..
3....2hw
.wh4w.w.
.....wh.
........`,
			16,
			16,
		],
		[
			map`
.h..w...
w....hww
w.w4....
2...w.h.
..h.w2..
...w.w..
h3.....6`,
			14,
			14,
		],
		[
			map`
.www..w.
..2..h.w
32..ww.w
...h...3
.hh.h...
.w...w.w
..4....w`,
			13,
			13,
		],
		[
			map`
.......h
.5h.h..h
........
...2....
.w.w....
..w..w34
6...wh.w`,
			14,
			14,
		],
		[
			map`
..hwwww.
......6.
.hh...hw
.....ww.
w.h...ww
.2....3w
..w..4.6`,
			13,
			13,
		],
		[
			map`
...w....
...w.45.
w.h.2..h
......ww
w...hw.2
5ww..w.w
h......h`,
			15,
			15,
		],
		[
			map`
6...w.wh
.w.h....
.www.w.w
..h.....
w...w...
...2.5w.
hhww3w.6`,
			12,
			12,
		],
		[
			map`
...w4w.6
....ww5.
.w....2w
....h.w.
..w.....
.h.2whh.
hw..w.w.`,
			16,
			16,
		],
		[
			map`
hww..w.w
.h..w...
......3h
....ww..
....h...
.4.....5
3w.2..hw`,
			14,
			14,
		],
		[
			map`
..2..h..
....w...
.......w
......h.
h..whww.
w.w2..h.
w4....45`,
			17,
			17,
		],
	],
	[
		[
			map`
wh5....h
h.3.w.w.
...hw.3.
...w....
3....h..
....hw..
..ww.4.3`,
			13,
			13,
		],
		[
			map`
...33..h
..5...w.
.2w.h.2.
hw......
w....h..
.hw.....
h...w5.w`,
			14,
			14,
		],
		[
			map`
...h..2.
w.3.h.w.
.....w.4
3ww...h.
.2h..h..
w.w.....
..h3ww..`,
			15,
			15,
		],
		[
			map`
.....24w
.23hw...
........
....hh..
.h......
5..w.h..
...h...2`,
			16,
			16,
		],
		[
			map`
..h.w...
....2hh.
w.h2..w.
w....h.3
w.h....w
.3www.ww
4....w5w`,
			15,
			15,
		],
		[
			map`
3w....h6
........
h..h....
....w...
.....h..
2w.2...w
w..h2w5h`,
			15,
			15,
		],
		[
			map`
..2.h3h.
54.3....
........
..h.....
.w.h..ww
.h.w..w.
.....h3w`,
			15,
			15,
		],
		[
			map`
2..h...h
....w.3.
..h.....
..h...h.
3w.ww..w
...w3h..
3w..w..3`,
			17,
			17,
		],
		[
			map`
.....w.w
.h.ww3w2
..2.....
...h.wh.
.2......
..hw5wwh
h.w..w3.`,
			17,
			17,
		],
		[
			map`
3....h.h
.....5..
..2h..2w
w.w.h..h
.wh...w.
..w..w2.
w3...w.w`,
			15,
			15,
		],
		[
			map`
h...ww53
..ww.ww.
...w.2ww
..h...w.
....h.ww
w4...hh.
3....3.h`,
			16,
			16,
		],
		[
			map`
3h5..ww.
w.w..h..
.w.ww.w.
.ww.22ww
...w.ww.
..h.h.w5
h6.wwhw.`,
			14,
			14,
		],
		[
			map`
6......h
w42.....
...hh...
hw...w.w
..h..3..
.....wh.
..w3w..6`,
			15,
			15,
		],
		[
			map`
........
.h.3....
w....h4.
..h..w..
ww.....3
54...hw.
.w2.h.hw`,
			15,
			15,
		],
		[
			map`
......6h
w...22w.
w..hwh.h
.....w..
.3.wh.2.
...w....
w.3.w..h`,
			17,
			17,
		],
		[
			map`
5.....w3
..h.w.hw
..w....h
..4....w
.w..w3.w
hw..h..3
w4.h....`,
			16,
			16,
		],
		[
			map`
w3....4.
h..hw...
.w.wh..4
.h.w....
...3h2w.
.5w.w..w
wh....w.`,
			17,
			17,
		],
		[
			map`
.....2..
..wh...h
6w.ww.h.
.5.w.wh.
4.....w.
.6.....h
....h..2`,
			11,
			11,
		],
		[
			map`
w2...3h.
..w3w.w.
..h.w..2
...w....
..h...hh
....2w..
..ww4.h.`,
			16,
			16,
		],
		[
			map`
hww.w.6.
3..4....
.3ww.w..
...h2.h.
........
..h..h..
..w2hw..`,
			15,
			15,
		],
	],
	[
		[
			map`
.h2h...w
3...2w..
.....whw
.2h...3.
...h..w.
.6..ww.h
.6..w..h`,
			14,
			14,
		],
		[
			map`
....w..4
.3.w..h4
.....w..
h.wh..hw
....2...
w...hwhh
.4.2..2.`,
			17,
			17,
		],
		[
			map`
h.h.w2hh
..3.....
w.wh.w..
3w......
.w.wwh..
w3.2....
h.4....3`,
			18,
			18,
		],
		[
			map`
.5wwwwhw
4.....h.
..2..23.
h..w....
2....h.w
..h....w
.h..h..3`,
			16,
			16,
		],
		[
			map`
h......3
..2..5..
2...h...
wwwh.w..
.2....4w
hwwh3.h.
whww...w`,
			16,
			16,
		],
		[
			map`
.h.....5
..w.....
22...h..
w.....w.
..h...2w
hh..wh..
..22..h5`,
			17,
			17,
		],
		[
			map`
www.wh..
h.h....w
2......3
.....whw
..23...2
hw.wh.2.
.....4h.`,
			17,
			17,
		],
		[
			map`
3.h3.w..
w...2..w
.2h3...4
....wwhw
.hh..hw.
.....w.w
2h...w..`,
			19,
			19,
		],
		[
			map`
h3.....w
.5h2....
......wh
....h.hw
ww.hw3..
........
6h53...w`,
			14,
			14,
		],
		[
			map`
.....w.4
..3.....
.3.....h
h.2..hhw
..3ww...
h.w3.wwh
hw..ww6.`,
			17,
			17,
		],
		[
			map`
3.......
hh...h.3
....h...
...h3...
333.....
ww...hh.
3.......`,
			17,
			17,
		],
		[
			map`
........
.3.....w
.h2w.2h.
...3h.3.
.w.ww.ww
..hw.hw5
h...2wh.`,
			18,
			18,
		],
		[
			map`
....4wh.
w......w
.....2h2
....h..3
...ww.h.
.43whh..
h.2.....`,
			20,
			20,
		],
		[
			map`
3....6.2
.h....3.
h......h
...hww.w
..w.3...
...3....
w3.whh.h`,
			15,
			15,
		],
		[
			map`
.....5.3
.....2h.
...hw...
w..h.hw.
..w.w.2.
..2.2...
h...h2.h`,
			18,
			18,
		],
		[
			map`
.......4
..3...ww
.h.2hwh.
.......w
.whhwhw.
.3...w3h
....42..`,
			18,
			18,
		],
		[
			map`
2...h3hw
..h.2..w
..w..w.h
.w.h....
w.h.w...
...w..w2
42..wh6.`,
			16,
			16,
		],
		[
			map`
.....5.5
..h.4hww
.h2..w4.
...2...w
hw.hw3w.
.....w.h
h.......`,
			16,
			16,
		],
		[
			map`
.23.w..h
w.3ww...
h...h.h.
.hw.....
w....h.w
...w.w2.
4h.3w..3`,
			17,
			17,
		],
		[
			map`
..2.2...
3...w.h.
.h.w.hhw
w.hw.w.h
...3..w.
.ww3.w..
5....h.2`,
			16,
			16,
		],
	],
	[
		[
			map`
.w.wh.wh.w
..h.....wh
....wh.w..
w...w.w...
..w4.w...3
5.ww4.....
w.w..4.hw.
..3w..w..w`,
			18,
			18,
		],
		[
			map`
.3..h....w
4.........
..4.w..w..
w....2w...
..wh....w.
h........4
.hh.h.....
.......3..`,
			17,
			17,
		],
		[
			map`
..........
h..h..6h..
....h....w
w...w..w2.
...2...2..
.w.w.5..h.
5..w.....w
w......h..`,
			18,
			18,
		],
		[
			map`
.w.5.....h
h...464w..
4..w.....w
....ww.w..
......ww..
....h.h...
...h.wh.w6
...w......`,
			16,
			16,
		],
		[
			map`
...3w.....
.w.32...hw
..w.3.h..w
.......4..
h.......4w
.h.......w
....w.hww.
wh.......w`,
			20,
			19,
		],
		[
			map`
.w.wh.w..w
w.h...ww..
wh.w.h.w..
3......3..
w.5wwwwh..
........4.
whww..5..w
...6..www.`,
			15,
			15,
		],
		[
			map`
4www..w...
2......w.h
.4h.ww.wh.
..........
2...h...w.
.w...w.w5.
.......w.w
h....wh.w4`,
			21,
			21,
		],
		[
			map`
.5....h...
....w.....
hw.3......
wh.....6h.
.www..w.w.
...w3.....
..2ww...w5
h.......h.`,
			15,
			15,
		],
		[
			map`
..hwwww..h
w.w4......
......h.2w
w....4..w.
.w..3w..h.
.25....w..
..w...h.w.
..hw...w.w`,
			16,
			16,
		],
		[
			map`
hw6..w..h.
.h.5....h.
...6.w....
.ww..w....
.whw..h..w
w.........
3.w.3..ww.
.6.....w..`,
			15,
			15,
		],
		[
			map`
.3..hh....
h...w..6.6
...h...w.w
........3.
..2w.wwhww
w.w...h..w
w.......2w
..w..w..w.`,
			20,
			20,
		],
		[
			map`
.h...w..w.
..2...2..h
.....hw...
...hwh.w..
w.5.w.....
w.......3w
.3.h...w..
5..w..ww..`,
			20,
			20,
		],
		[
			map`
2..2......
h.h.ww.w..
5wh..h..h.
...w...3ww
.w.w..4...
.w......w.
.3........
.....hw...`,
			19,
			19,
		],
		[
			map`
.....h...4
.w..w....4
.w..w....3
...3ww..w2
..h....h..
wh..5.h...
........ww
.w...h..w.`,
			18,
			18,
		],
		[
			map`
.h4..w....
....w...6w
h..5.w..h.
..w.ww.w.h
.......wh.
.5......w2
4.........
.w.ww.wwh.`,
			15,
			15,
		],
		[
			map`
.4.ww.h.w.
ww5.w..h.h
w..w.w.w..
...ww..w2w
.....w..w.
.w..h..h.w
.......www
3.w.w.h.23`,
			19,
			19,
		],
		[
			map`
....4.....
.4.w..w...
.5.....h..
..4hww....
........hw
..ww...3.2
h....w....
ww...h.wh.`,
			18,
			18,
		],
		[
			map`
..h..w...3
.........w
......h...
.......w..
h.hww..2.w
.3w..ww.5.
.w..ww4.hh
....w..4.w`,
			18,
			18,
		],
		[
			map`
w.......w.
2......4.h
..hw.h.w..
hhww...2..
.....h....
.w.w4.....
2w....ww.w
5..w..w...`,
			19,
			19,
		],
		[
			map`
.......4w.
..h.w.....
.....hw.w4
h2..w..w..
......w...
...w.....w
.h..w2..wh
..36w..h.w`,
			18,
			18,
		],
	],
	[
		[
			map`
ww.....wh.
.ww.h.w.w.
h.wwww.h..
.34......w
....w.w.w3
2w.hw..2w.
w...h..w.w
w4......4h`,
			18,
			18,
		],
		[
			map`
.......hh.
ww.w.h....
w5.w......
........4.
4..w.hw..w
........w3
...3h..6..
.h5wwh....`,
			19,
			19,
		],
		[
			map`
w...hw....
2ww.......
.2.2.wh3..
........w.
h.h..ww.w.
wwwhw.wh.w
4....5....
6......wwh`,
			18,
			18,
		],
		[
			map`
..w.3w..w5
w..hwh..3.
w.....w.w.
.h........
ww..h..3h.
h..w......
......42..
w......w4h`,
			21,
			21,
		],
		[
			map`
.w..w...wh
..hw...w..
.h...ww...
..w..w.w.3
w.2....w.w
.2..h.w5h.
.w.h......
4wh...3w.2`,
			20,
			19,
		],
		[
			map`
.54.ww.ww.
h.....w32.
.........w
.w..h4....
w..w....h.
.h....3..h
5w..h.h...
.......w.w`,
			18,
			18,
		],
		[
			map`
.........h
.h.2.....w
w.5...2..w
.w..h..wh.
...w...w.w
..w..w...w
6.wh...4.6
.3..w.hwh.`,
			17,
			17,
		],
		[
			map`
..2..hww..
w..ww4.w..
....w...ww
.3..w..w..
....h.2hw.
.w.ww.....
4...h..wh.
5.....h2.h`,
			22,
			22,
		],
		[
			map`
.....4.ww.
2...w..h.w
..hw.....w
.....wh4h.
..h...ww.w
..ww3.w...
3.w5...w.h
.h.w....4w`,
			19,
			19,
		],
		[
			map`
.ww5.w....
w..wwh.w..
w2......ww
3w.h......
.3.w.....3
.h.w.ww.w.
h..2.h.h..
6w..w.h...`,
			17,
			17,
		],
		[
			map`
...w....35
h2.....ww.
...h....w.
.2..h....w
..5.w.w...
..4...hw.h
.hww.w..hw
.w....w..5`,
			19,
			19,
		],
		[
			map`
...3...w.w
.........h
.....2....
.......h..
.hw.wwh...
6...w.hw5w
w.h.....2.
....2whww3`,
			18,
			18,
		],
		[
			map`
.h.....2.h
4.w...hww6
...ww3.wh.
w..w..w.3.
w4....2www
.w........
..w..h.h.w
w.h..w..w.`,
			18,
			18,
		],
		[
			map`
6w..3.....
..h...w..h
.....h....
.wwh....w.
wh3.w..h..
....4...3w
hww...3w..
........4w`,
			19,
			19,
		],
		[
			map`
2.2.ww3..h
....h.....
..........
h.hh...w..
.3.......w
w3.whw..w3
5w.....w..
...ww..h.w`,
			19,
			19,
		],
		[
			map`
..w..w...5
..h...w2..
.....w3..h
.w.h......
43.....h..
w.4w.w...2
..wh.whwh.
w.........`,
			20,
			20,
		],
		[
			map`
.w........
ww3..h.w6w
hhw.wwwh..
....h.w.wh
...w..4.w.
2w...w.2w.
.....w.3.w
.3h..w.w..`,
			22,
			22,
		],
		[
			map`
..w.w..6wh
...4h.h...
w.2.......
3w.....w..
ww.w...3..
whh......w
.....w...3
wwh.w..h4.`,
			21,
			21,
		],
		[
			map`
.......w.h
...hw5h...
..3.......
4h..h...w.
.........w
...w..4.5w
..........
hh.34..w.w`,
			19,
			19,
		],
		[
			map`
.ww3.w...h
.w.....w..
..ww.w....
...h.w....
ww...2..h.
w.2h.w..2.
..4.......
6.hww3.h.h`,
			20,
			20,
		],
	],
	[
		[
			map`
.w..w.32w.
ww..w.w.6h
wh.w..w5.w
..w2w..w.h
ww..w4.w..
.hh.hw....
..2...h.w2
....w...h.`,
			21,
			21,
		],
		[
			map`
...5......
....42.4.w
..hwh...ww
.3.......3
...w.hww.w
w.2h..w..w
.....w...h
hh.ww.w6h.`,
			20,
			20,
		],
		[
			map`
.........3
..3.w....w
..w.3.h.w.
.w..2..ww.
..h..h..hw
5..2..w.w.
.h..h..2wh
..2..h...w`,
			23,
			22,
		],
		[
			map`
wh35.w.h..
hww...2..h
....hw..4.
..h.3...w.
.4...ww.w.
www.w.wh.w
..h......w
....44.ww.`,
			21,
			21,
		],
		[
			map`
..wh.w...6
...h..ww.4
.....w..4.
.wh....4..
3...33..h.
wh2w.w....
..w..w.w..
whh....h..`,
			21,
			20,
		],
		[
			map`
5.w.w..4h.
..3....h..
.....w...5
.2wh.3....
...3.....w
h.ww4.wh.w
.h..w...w.
w.hh......`,
			20,
			19,
		],
		[
			map`
h....42..6
..2w3.w.h.
........2.
.h..ww.h..
..h.h....w
.4ww....h.
.....w....
ww.h...w.6`,
			20,
			20,
		],
		[
			map`
3.5.w..hw.
.ww..h..w4
..4.....w.
...w....3.
..hwwww.w.
...2.2...h
ww..hww.hw
....h.h4..`,
			18,
			18,
		],
		[
			map`
.......4..
.hw4..whw.
.w..24.w..
hwh4.w..w.
.w........
w.hw.w...h
...w..h...
w6w.3w..2h`,
			19,
			19,
		],
		[
			map`
.........h
w5h..2.whh
w..h.w....
3.....3hw.
w..h...w..
..........
.......3w.
2..h4.ww.3`,
			23,
			23,
		],
		[
			map`
5...w...w.
4w.h...4w.
...h.2.h2.
.....w....
.....w....
..w....wh.
..2whww..h
h4.wwhw4.w`,
			21,
			20,
		],
		[
			map`
h.........
.h3.w..6hh
.3.w.w.w..
w....4ww.w
....4..w2.
....w.w...
6......w.w
h.h4.h.hww`,
			19,
			19,
		],
		[
			map`
.h...4..wh
2...w....6
..h.5.w.wh
....w..w.4
h.....w...
..2w.....w
.3hhw...w.
2...w..h.w`,
			17,
			17,
		],
		[
			map`
5h..24...h
.4.w..wwh.
w..wh.....
......3.w.
ww3....w..
h.ww.ww..5
..2..w....
h....h..h.`,
			21,
			20,
		],
		[
			map`
....w5.2..
..h...ww.h
......h.w2
...h..hw..
.w.....2..
w4....w.4h
.wh..w...3
.w..3....h`,
			25,
			24,
		],
		[
			map`
..h5.2w...
..2..w...h
...w....h.
....hh..3.
..h...3w..
wwwhw.w...
w3........
4w..wwh..6`,
			18,
			18,
		],
		[
			map`
5.......wh
....w..w..
w...w.3www
.h3...w...
w33.w.whw.
....h...2.
.ww...h...
6hw2whwwwh`,
			23,
			22,
		],
		[
			map`
.h......42
....4.....
.....w..4.
....w..wwh
...2...33.
.hw..2...w
.h....hh..
w..hh.....`,
			22,
			22,
		],
		[
			map`
.h.....h.h
hw..wh.h.6
.w2.w.....
...3ww..w.
.h..3..2..
w.4.....3.
.h....5.ww
.w......w.`,
			23,
			22,
		],
		[
			map`
.hh...4..w
..6..4....
...5w..w..
w..h..w...
3.w..h..w.
..........
.3.2h.2.h.
h........h`,
			21,
			21,
		],
	],
	[
		[
			map`
3...w..ww.w
....w....2w
w..w3w.hh..
....w...w.h
w.h......4.
w..w..w....
..hhww.hw..
.2......5..
5..........`,
			21,
			20,
		],
		[
			map`
3ww3.w.w.5w
.w...5...w.
..ww....2w.
....w.h.3..
wwhw...w...
w....3.....
.whh.......
ww.w..hwh.w
..w....h.w.`,
			23,
			23,
		],
		[
			map`
w.4.....w.4
...........
55.wh4.w...
..ww...5.h.
...h.......
.w.w.......
.w....ww.w.
h.ww.hw....
w....w4hh..`,
			20,
			20,
		],
		[
			map`
h.w3..ww..h
.......h.ww
...wh...w2.
2..........
3hww..w.4..
.3.w.h.w..w
..........w
.w......w4.
..hww.ww..w`,
			21,
			21,
		],
		[
			map`
hw.....4...
....h...h.h
.3.........
.w4.w..w...
...........
...w.w....4
6w...h..w..
...w4.....w
.h..h.....6`,
			18,
			18,
		],
		[
			map`
.......w..w
.whw...w...
w.w...h..3.
..53....h..
w...w4.....
w2ww.w....3
...h.w.h...
...w4.wwh..
wh.w.....w.`,
			22,
			22,
		],
		[
			map`
w.w.w2..h..
.....4..w..
..h.....3..
.w.h.......
3......ww.w
wwh..2..ww.
.......h...
w...wwhw.hw
.w2..www5..`,
			21,
			21,
		],
		[
			map`
..w.w.6....
.wh.....hh.
......hhw..
..w........
ww...3w...4
...w.wwhww.
..w.ww..w..
3...w.ww63.
..w..h6....`,
			21,
			21,
		],
		[
			map`
.ww..w.....
w.5ww3.w..w
w.....h.ww.
hw.......hw
...w......h
.h.w5wwhw..
3..........
.wh.w.43...
....3ww....`,
			21,
			21,
		],
		[
			map`
w...3...w..
3....h.3...
...w..hwh..
..ww.....h.
..........h
.whw....3..
.w..h.ww.w.
.4ww..w3...
w.4..w.....`,
			22,
			21,
		],
		[
			map`
4........5w
...wh.w....
......h....
..4.ww....h
h..5.....w.
.4ww..h.hh.
.....w....w
ww.....w...
.4.......w5`,
			18,
			18,
		],
		[
			map`
.h...44.wwh
.w.ww..ww..
.4....w..w.
..w.4ww....
.........h.
.......ww..
.w.h...3..5
..w..whww..
.hhww...6ww`,
			19,
			19,
		],
		[
			map`
6...3...w.w
.........h.
....3ww....
..w..4...hw
.w......h.4
w.ww.....h.
h...w.3w...
...w.h..2.w
h.w...w....`,
			21,
			20,
		],
		[
			map`
3.w.w...w..
6w.....hw..
.........2.
...h.w....w
....3w..h..
..w.6..w...
..hw.ww..2.
...wwhwhhw.
..w3...w..w`,
			21,
			21,
		],
		[
			map`
.wwh.w.w..w
.w...2h..w.
63.w....h..
..4.w......
w4.w...w...
w...2......
.wh..h.....
ww.w...wh.w
h.w..5...w.`,
			21,
			21,
		],
		[
			map`
5w4w.....w.
.....www4.6
.2.....w...
.w...3w..w.
...........
hh...whw..w
.w.4.....w.
.....whh..h
.w..h......`,
			19,
			19,
		],
		[
			map`
5.w..w..w.w
w.h.w.....4
w.....w.w.5
........h.4
ww.h......w
hh.w.......
..........w
w.....4w..h
w2wh.....6.`,
			18,
			18,
		],
		[
			map`
..4....w.h.
......ww...
..h...w...5
..h..w.ww..
3.....w..2w
2..w....w..
..........w
..h...w.hh.
h......3..5`,
			22,
			22,
		],
		[
			map`
..w...3w..w
..........3
4.w...w.hw.
.w.h.....3.
..h.hh...w.
w.....w4.w.
.ww..w..w.h
.....2...ww
...w4w....h`,
			23,
			22,
		],
		[
			map`
3.....hh...
.w.ww...hww
..w...whw.6
.2....h..3.
...ww....ww
..hw....ww.
.w....2w5..
...w5.ww.w.
h........w.`,
			21,
			21,
		],
	],
	[
		[
			map`
.....w3...w
....w......
..ww.ww2w..
...h.w...h.
..h...wwh..
.3....w..w6
h.w.w.3w..w
..2....w3w.
.h.h.h..2w.`,
			23,
			22,
		],
		[
			map`
.4........3
.w....w...w
w3ww..w..h.
...........
h..wh.wwh..
h.ww.w...w2
.w4..w.5h2w
..h.w.ww..w
.....ww4..h`,
			28,
			27,
		],
		[
			map`
4....w.w..w
....wh...w.
w.hw..h..w.
.....w..h..
w2.h4.ww.w.
..ww.5w....
h.w....w...
..3w.h...w6
w2w..wh.w3.`,
			24,
			23,
		],
		[
			map`
3wwhww..w..
hw...3ww.ww
.6....4.w..
..h....w..w
2........w.
..ww3ww....
.w.....hw..
..h.whw..w.
wh..24..w.h`,
			20,
			20,
		],
		[
			map`
...2..5....
.4w..h...h.
.w.ww......
...w.w.3hh.
......w2w..
..h......w.
......3...w
...w....4w.
....hh.w3.h`,
			25,
			24,
		],
		[
			map`
..........w
..3.....wwh
.....2h..hw
www..w.2..w
......hwww.
hww..2h...w
w.ww...w6..
....w.hw...
.hw.44....4`,
			26,
			25,
		],
		[
			map`
.w...w....w
..h.2..h3.w
.....wh....
3ww..w...32
.w3w.4...w.
w...h.h..h.
.4w.h..ww.w
h......w...
......w.w..`,
			25,
			24,
		],
		[
			map`
w.3........
...hw......
..w.....w2w
.......h...
..w3hw...2.
.w.ww..w.w5
..hw..h...h
hh.w2..w.w5
w.....3..w.`,
			27,
			25,
		],
		[
			map`
.4w.w......
.whww.w.6.h
5..w.wwhww.
..4....ww..
.......w.ww
w.h..hw....
.w......2h4
...w..h...w
2..h....3w.`,
			23,
			23,
		],
		[
			map`
.w..ww..w..
h..3...w.h.
...3.ww...6
....ww.3w.h
.w.....w.hw
......w3...
.h...w..h2.
......3....
4.ww.w..h.h`,
			26,
			25,
		],
		[
			map`
h....w6...w
6.....hh.w3
5..........
w.....5.h.w
.w.3......2
.....w.3w..
w.h..w..w..
...w......h
..w.w.h..h.`,
			22,
			21,
		],
		[
			map`
....w.h.w..
w4........h
...........
hw...w.w..w
h..4.....4.
.....wh..w.
..whw.3.5..
.w.h.....w3
4...h.w..5.`,
			22,
			21,
		],
		[
			map`
...4.ww.4..
..h...h...h
....w......
www.h...3..
..w....3w..
.w..4w.w.w2
w.w.ww..h.w
.wh..hhw..w
...w2.....3`,
			24,
			23,
		],
		[
			map`
.ww.....w5w
ww.5w..wh.w
w.w.4.w.wwh
.w2.w..w...
...ww...h3.
.h.3..w..w.
h.w.....w..
.w2.wh.....
h.....whw.3`,
			24,
			23,
		],
		[
			map`
h.w2w......
.......h.ww
.32..w.....
..w.hw..whw
......42...
..w........
..2h....h.w
6w.hw..w.w.
wh........4`,
			26,
			25,
		],
		[
			map`
5.w.w.....2
h.h......w.
...h.wh...h
..w..w..w.w
...........
..w3.......
.3..5h...hw
3w.2w..whw.
w.4........`,
			25,
			24,
		],
		[
			map`
.ww.wh3...w
.........w.
5...3......
...h.....h.
.......w.42
.3...wh..w.
.wh........
...w..w.4wh
.hww..5..h.`,
			23,
			22,
		],
		[
			map`
6......h...
wwh3w.w....
w6ww..w....
.ww.wh.2h.w
ww....w....
..wh.w...w.
....w..w3..
ww6h.....6.
.h..6...wwh`,
			18,
			18,
		],
		[
			map`
.w.54w...2w
5w.....h...
..w........
....w....hw
....h....h.
..h..w.....
h..2...3...
.w.w.h4w.wh
......w..4.`,
			20,
			19,
		],
		[
			map`
.www....4.w
hw......w..
..w...wh.h6
.......h.w.
.2hhw......
....2.ww.ww
...w......w
3h.....43..
..w4h......`,
			22,
			22,
		],
	],
	[
		[
			map`
hw6.......h
...........
w6w.h3.hww.
....3w.....
w...w......
...w.h..wh.
3.h.hh.w6..
ww..w.ww..4
.....w.3.2.`,
			27,
			25,
		],
		[
			map`
26....h...4
..3ww..whhw
..whh......
hww..w23..w
.w.....w...
w..2..w.w..
.h........w
w.hw5.w....
w.w..4w.hw.`,
			23,
			22,
		],
		[
			map`
..4w...w..3
.h...w5...w
..h.w.hwh.w
2..........
.2wwh.h.www
.w.3w3.w.w.
.....ww...h
whwhw....4.
.w....w.3.w`,
			27,
			25,
		],
		[
			map`
2..3......w
w.h2.hwwh..
...w.h....6
h2..w..h...
...w....h.w
w.w.h.w..3.
.hw....2w.w
w..w..3...w
w3.w.......`,
			27,
			25,
		],
		[
			map`
2..3.w..h.w
.hh.w....w.
.....w.....
h.whwwhw.h.
.33....w..3
....3..3w..
..........4
.w.ww.ww..w
h...6w..wwh`,
			24,
			23,
		],
		[
			map`
.hh...3.w..
w......2...
..h3.h...h.
.w...w.w..w
.2.........
3.2..w...w.
h.w.w.h....
.w...5.h.w.
...h45w....`,
			27,
			25,
		],
		[
			map`
...w..w..ww
h...hw.2h.5
.w..www..hw
.4.........
.w.....hw.w
........4.w
...h.h....h
6h42w.4...w
5..........`,
			22,
			21,
		],
		[
			map`
3wwhww..w..
.w...hww.ww
3.......w..
4......w.hw
....h.4....
.3ww3ww..h.
.w......w..
h.h.w3wh2w.
wh...5..w..`,
			24,
			23,
		],
		[
			map`
.w........w
.hh...w.6..
..2.www....
...w....4..
.2....w.w..
.3h...3hh.w
6....w..ww.
.whhh3....2
........h..`,
			27,
			26,
		],
		[
			map`
w.3h....w..
6.....h..hw
.....h.w...
ww.....w...
...44.w..2h
.h.h..w..w.
..w....w3..
h...w.6..h.
...2w....4.`,
			22,
			21,
		],
		[
			map`
w4hwh.w.4..
2..wh4..w..
.w........w
..2....h.w.
h.ww...w..2
ww..ww.wh..
5..w..w.h..
.w....w2w.h
..4.w....h.`,
			28,
			26,
		],
		[
			map`
.w5ww.4..wh
w...h......
6...h..h...
...2....hw.
.3ww..3....
..h.2.ww..3
...h..w.h.w
.........h.
.w..w.w...3`,
			25,
			24,
		],
		[
			map`
.h.h...3...
h...ww....4
...w.....h.
w2w.hhw....
...2.......
......4wh2.
ww...w2h.w.
3...ww....w
.www...h2w.`,
			25,
			24,
		],
		[
			map`
.ww.wwh...w
hw.w4....w3
4.ww.w...h.
......2....
.h..w.w....
2hw..w.hw..
...3.......
.....3w...h
h2w.h....3.`,
			24,
			23,
		],
		[
			map`
..w.....w..
....3h.w2..
...w......h
..w3.w.hwh5
wh.hw.ww5.w
...w..6....
3...w4.....
....4..whw.
....h.h.w..`,
			24,
			23,
		],
		[
			map`
..........w
w.hh..hwh3.
w....w.....
h3..3...w..
w4...3.w..4
....h..h...
........w..
..6..3ww.hw
3..w.h.....`,
			26,
			25,
		],
		[
			map`
.....w...5.
w.3...hw...
....3....w.
..........3
2hhwwh...ww
...w.....wh
..h...3hw..
h..w..w.4..
..wh..23...`,
			29,
			27,
		],
		[
			map`
w.6h....2ww
.w....h.3.h
33.w.......
.....h..w..
...4.h.....
..www.2..ww
w..w.w..hw.
...w..4....
hh.h...4..w`,
			25,
			24,
		],
		[
			map`
w5......w.h
....3......
4..w..hwhh.
..ww....h..
..h....h...
.w.w.2...3.
.w..4.ww.w.
...wh.w....
w...hw3.5.4`,
			25,
			24,
		],
		[
			map`
..h3.....hw
4.2....w.5.
w2.h.w...h.
.......3w..
w.h....w...
......3.2..
2.......w.h
..h..hww..w
...w...h...`,
			28,
			26,
		],
	],
	[
		[
			map`
.4........4h
wwhw...h....
w..w.2......
4....w.h..w.
...w..w..w..
........w...
........36w6
h.3wwh.hh...
..w..hw.w.5.
..h....w5...`,
			31,
			29,
		],
		[
			map`
wh.w....ww..
..w3ww2w.h.w
...w3.....w.
.....ww.wh3.
.w..w.3.w...
4...wh.hw...
..6........h
.4.h.....3..
.....w.whw..
h4.w......h.`,
			32,
			30,
		],
		[
			map`
......hw...w
....w5......
.4...w...6.w
..w.3...w..2
....h.w2.h..
...w.....w..
..w.whh...wh
ww.h......3.
...h.w...w2.
5.w...2hh..w`,
			31,
			29,
		],
		[
			map`
hww..w.....w
.w5....wh.w.
..ww6w...4.w
.....whh....
ww........w4
w....w..h...
6.h..2.2.hww
...ww.....4.
..2.h.h..w..
hw...w...6w.`,
			25,
			24,
		],
		[
			map`
2h..5h.w2.h.
.....3......
..ww.w......
h.w2.4.ww...
..hw..w.....
w...hw.hw...
33whw.......
.w.w........
..ww....w.36
...hww...h..`,
			31,
			29,
		],
		[
			map`
......h..2w.
.....hwh....
w5w....6w5..
...h......w.
....h.....5h
.....w..4w.w
.ww2w.6.2.ww
w..w..w..h..
..w..w.h.h.w
.w..w.6.w.hw`,
			27,
			25,
		],
		[
			map`
2w...w....w.
.w.5.4....6.
..w..h...w..
h...w.....ww
....h.......
.hh..w.....5
...h....hh..
3w.w2..w.w..
.2....w3hw.w
..h..w....2.`,
			30,
			29,
		],
		[
			map`
w.wh.4.w..h.
.w.w........
w2hw2.w.w..4
....3w.w.w6.
w...w......w
4h.....ww3..
...h...3..w.
.w....h.h..w
ww3..w...h.w
..w...w...hh`,
			29,
			27,
		],
		[
			map`
h..w......5.
.w.h..2.h2ww
.w...w.w...6
....h.hw....
..w3.....hw.
......ww.4w.
.w.wwwww.h..
4w..3w..w.w.
.wh...h..w..
w5.w.wh...w3`,
			29,
			27,
		],
		[
			map`
.h....4....3
....4....w..
h........h..
.2h.wwhwhw..
..w.....2ww.
...h.......4
w..w....h.ww
.....4......
3ww....h.6..
5....hww.w..`,
			28,
			26,
		],
		[
			map`
......6whw..
.5.w.w..ww.w
w.h..w.hh.w.
...hw2...3w.
w2h..w......
...w....2...
.w.3....w...
..3wh.....hw
w.5.w...w...
......h..h.5`,
			32,
			30,
		],
		[
			map`
..w.5...w.ww
......4..whh
w..w3...w...
.w...h5.w..w
........3...
h...........
.wh..w......
5w.wwh.....3
2..h..h...4w
..5.....h.h.`,
			30,
			28,
		],
		[
			map`
....4w2..hw.
.......w...5
.h......wwh.
h...w.3....h
.w.w..w.....
4..whw......
.w3......hw.
.w..h..hh...
.6w...2...3w
.....w..w.w3`,
			30,
			28,
		],
		[
			map`
..3w..w.hwww
....4w..h..2
.wh.www.3hww
.......6.236
.w.h....w.w.
..........w.
..2....h.h.w
....w.....ww
4.......hh.w
.wwwwwh...w.`,
			30,
			28,
		],
		[
			map`
h.w..w.4..w.
...h..ww.6w.
6....w......
3w..3.4....w
.....4....w.
w..w.w..4...
..w..w.w...h
w....2......
...2..wh...h
hhw.hw..h.h.`,
			27,
			25,
		],
		[
			map`
.w.....w....
42w.h....w.w
w..h.....h..
.w.ww....w..
w.w..h3wwh.4
..w..3...2w.
....2..hw3.w
..h.www...w.
...h.....w5h
3..ww..h....`,
			31,
			29,
		],
		[
			map`
w..w3h.w...3
.....w......
h...hww...6h
wh.4..w.....
.....wh.w...
2..w.....w.w
.25w....3w..
..w.ww.w.w.w
h6....w..wh.
ww..3.wh..hw`,
			31,
			29,
		],
		[
			map`
w.hh.h..w..w
h6.....4..w.
.......w.4..
ww2...3wh6..
......w.....
......w..w..
..w6...w2...
3h..w......h
...2wh.h...w
.h.....ww...`,
			30,
			28,
		],
		[
			map`
....w.3...2.
....4.wwh2..
4h...2..w...
...h...w..hw
.w.....2...4
w....hw...h.
.w.h.wh....w
.w..4.......
..w..h......
hww.......4.`,
			31,
			29,
		],
		[
			map`
h....3.w...h
w.h.w.w....3
.....w......
...h...ww3..
ww.w..ww.wwh
w3w2.......4
.w....hwh..w
42h.4..w..6.
......w..w..
..hh.w.w....`,
			32,
			30,
		],
	],
	[
		[
			map`
.w...35ww...
h.5.....3...
w2........hw
hww.wh......
w...h.wwhw.h
.hwh..w..w.w
..w..2.....5
ww.w...w4...
........w5.h
.ww5.w..h2..`,
			31,
			29,
		],
		[
			map`
w3...wh4....
.ww6...w.hh.
..h..w.5....
4.......w...
..h..ww.whw.
wwwhw.w.3www
.2.........2
.w...h2wwhww
3.w.......ww
ww..hh....w4`,
			30,
			28,
		],
		[
			map`
h.h.....w3.w
.w..hhw...5.
..w....h...w
.wh5....3.w.
w...h.......
5.w.....w...
....w.3w...h
2w.w......h.
w.5......h.w
h4w.....3..2`,
			29,
			27,
		],
		[
			map`
4w..ww.5wh.w
.3..w3.h.ww.
...w...3ww.w
...h.....3..
.........w.3
..ww3...w.h.
..w.w2......
.h......3w..
...w..hh....
.h.h6.....hh`,
			34,
			32,
		],
		[
			map`
4....5......
ww.w....6...
w6.w.......2
....2w.4h.w.
...w..w..w..
.....h3.wh.h
..........w2
..3wwh.h....
.hw.h.w.w2..
.h.....w.h.h`,
			31,
			29,
		],
		[
			map`
h.4..w..w..w
.h2.h...2.h.
..ww...h....
2w.2w....hw.
.2hww3..h.2h
.....w...5..
....w.h.w.w.
wwhw4.ww....
......w.ww..
..w..w.4w.ww`,
			35,
			32,
		],
		[
			map`
.ww3...w4.h6
w..w...w.w..
w.3.2...ww.w
.....wh.w2.w
.h.h.....ww.
......4.w...
..hhh..2whwh
w...wh.w.w4.
..w.....w..w
.52....h..w.`,
			28,
			26,
		],
		[
			map`
h...wwh.w...
.52ww.w.....
....3ww...34
.....w2..hw.
..hh.....4w.
5.....h.w..w
.hw.......w.
3w....w...w.
..hwhw.h.h..
2...4..w..w.`,
			31,
			29,
		],
		[
			map`
h.....3w.h..
.h.3........
..ww.w..hh..
3.w....ww...
...w.4w3h...
w..2.w..w.3.
.hw.w.h.....
.w.w........
..ww3h..w3h4
h.6.ww......`,
			31,
			29,
		],
		[
			map`
h6hwwww4ww..
...2.ww.w...
2...5....h..
h....3h.....
...h...w...w
...w..www.4.
.h3w...h...h
.ww..w......
5..ww3...w..
w2..h.w.wwh.`,
			30,
			28,
		],
		[
			map`
..hw...4.h.w
2....h.ww.w.
........w..4
53.4h...hw.w
....w2w.....
..3....w..3.
.hww.wh..ww.
.w.h..w...hw
.....3...w.w
h.w..w3w..h.`,
			33,
			31,
		],
		[
			map`
h.2w4..w..4.
.....w....w.
.hh.wh.whhww
...2.......2
..ww...hwww4
.wh.w..whw2.
.....ww.....
whw.w....h.w
4w...3w...w.
4......5ww..`,
			33,
			31,
		],
		[
			map`
.w.....4.wh.
.2..h3.....w
h........3h.
..3.w3.....w
.h..h....w.5
.w...2.w.h.w
w..h......w.
...w2h.w....
6w...w......
..hw..2..h.w`,
			31,
			29,
		],
		[
			map`
..4.....w...
.4.5..w.h.hh
w.w..3w..w..
....w..w....
....w..4.w..
4...2ww.wwh.
.w..wh.hw..w
.w....w.3...
.h..h.2.w...
h.h.h..ww4w6`,
			32,
			30,
		],
		[
			map`
h..w.5.hh..2
4.ww..2....w
.....w.w..4w
...ww......5
..2...h.w..w
...h...www..
w5.h2.w.3w..
..hw..ww....
.w....wwh4.h
.ww.hh.....w`,
			32,
			30,
		],
		[
			map`
42....42....
.w.hw3...ww.
.4w.......h.
...www.hh.4.
..h.w..w...4
w...w.w..2ww
.h.....hw.w.
...h....w.h.
..w.....wh..
.h4ww....4.w`,
			33,
			31,
		],
		[
			map`
6........w.h
3.w3w...h.ww
.53..h2.....
ww..w....2w.
..w.....w...
.....hhw....
..w.h...www.
hh4..w......
..6....whww.
.h....w3..h5`,
			31,
			29,
		],
		[
			map`
...w3.....h.
.w..w.5ww.w.
..2.......4w
3.wwh...w...
...w.3..w3..
.w.ww.....4.
..2...hhh...
.h.......hww
...w4ww..w.h
h.hwh.3.w...`,
			32,
			30,
		],
		[
			map`
.h.4.....hw.
.......w...6
h..w.w...3hw
....w..w...w
......h.h.wh
.....w3.....
43w.6h......
h...w....w.2
..2h.....w3w
hw..w......4`,
			30,
			28,
		],
		[
			map`
........w.4h
ww..w.w.....
4.......ww3.
..2....w....
....h.w..ww3
.5ww...h.h.w
....whhww.ww
2..w3...4ww.
....2....w.w
.h.hw.h.h4h.`,
			35,
			33,
		],
	],
	[
		[
			map`
.w3...2.wh.h
h..34..w....
4....5.h..2h
.2h..w3.w...
.........hw.
.hw...w.w...
........w.ww
.....h.w.w4.
.........w.3
.wwhw.h2w.hw`,
			33,
			31,
		],
		[
			map`
3ww.w3...2..
....w3w...5h
...h.ww..h.w
.....2.....2
.2hw...wh...
.........w..
h..h...w...h
.h.w..hw...5
w....hw....w
..43ww5.w..h`,
			31,
			29,
		],
		[
			map`
..hh.w5...w.
....w3......
.2ww.ww3w.h.
.....w...5.w
.h...5ww3.h.
.h22..w..w2.
..w.w..w..w.
....3..w.w..
..hh..h..wh.
h4..w.....h.`,
			38,
			36,
		],
		[
			map`
ww.........5
w...h6..w.3.
hh.w...2....
.w.2...hhhw.
...2..w.....
....w..w...3
.wh.h..22h.w
.5www..ww.h.
.w...2..h...
4..w...hww.w`,
			30,
			28,
		],
		[
			map`
.3......ww..
3.wh..w.....
..6hw....hh.
....h3h..w..
...........3
....wh.w..2.
.h.w....w...
h2ww.wwww.w.
..h3w2.4.h..
w.hw3.3.w..w`,
			34,
			32,
		],
		[
			map`
w.h........4
wh...hw..hh.
h......wh...
..2.hh.3...w
www..w.3..2.
...w.w3.2...
.5...3..ww.w
..w4.w..h...
3.w.w.h..w..
.3w.....h..w`,
			33,
			31,
		],
		[
			map`
............
h......h....
...h.....whh
...h..h...w.
23.........h
ww.....h3w..
.h.2........
.w.hw4..w..2
.....2w2w46.
.3.w.6ww...h`,
			29,
			27,
		],
		[
			map`
.hw3w.....5w
......25h...
..4..w.....4
h.w..w.wwhhw
....w.h..ww.
w.w.2.w.....
.w.h...h....
...w....344.
....hw.h.h..
35...h.w..w.`,
			33,
			31,
		],
		[
			map`
.2h.w2.ww...
2.......www4
..h.4h.w.ww6
.hww..w.w.h6
hw.......w.w
4..ww....3.w
.h.w.......w
.w..hw....w.
.w...w..hh.w
.w..w6h.w35h`,
			29,
			27,
		],
		[
			map`
.hh.ww.w.2ww
...4.....w3.
.h.w.wwhh..5
..2wh.hw.w..
......w.....
...h...hh.w.
.www..w..w..
..h.w.4w...h
.3...4w...3w
4..2....4w..`,
			32,
			30,
		],
		[
			map`
h.w.w.6.2..5
hw.......3h.
..2.h5..w.hw
5.w.........
ww..h.w.h4..
...w.ww.ww..
3.w.ww.2h...
....w.ww....
hhw......h5w
...2.wh...w.`,
			33,
			32,
		],
		[
			map`
..w.w...3.wh
.2..w3ww...h
....hw......
..h3hw..hhw.
.w.....h.w2.
..ww......43
....ww.h...3
wh....w.....
w.w.3......2
..w...62hh.w`,
			35,
			33,
		],
		[
			map`
6....whw..ww
...ww3w.....
h.........hw
..4..w.hw...
..h......h3.
3h.w.ww..w..
h.w..wh2...3
..2.w.w.5w..
5.....w..w..
h..35..wwh.h`,
			29,
			27,
		],
		[
			map`
4....wh....w
.w2...w.h.w6
.2.w.w.2.w.w
hw.....w...w
..hw.hw2....
.h.w.....h.w
...3h...w...
.4....w3...h
6....w.2...w
h.w.w..4wh.h`,
			33,
			31,
		],
		[
			map`
.3..2w....ww
..h.wh...w.6
3...2w.h.4..
..w.ww.w...w
...h...w2...
....h...w...
..hh...h..5w
.w2ww6ww..wh
h.h..w.3ww.h
....2..ww...`,
			32,
			30,
		],
		[
			map`
..w.w54...hh
.........w4.
h3...w.2....
.hw..w..whw2
.........h..
2.w.h......5
h.hh....hhw.
.w..w..w....
w...2..2....
36........w.`,
			32,
			30,
		],
		[
			map`
..2.......54
wwhwh.5h....
w..w........
....3w..4hw.
h5.w..w..w..
.......3w.4.
..5...h...w.
2..ww...h...
..w...whwh..
.h..h..w3..h`,
			28,
			26,
		],
		[
			map`
h.........h.
w.....3.w..w
..h3hw.w3.w.
3...w.....w.
h..w....hhw.
.5....w.w..w
wwww4h...w..
..5.hwh..2..
.....5...ww5
..2..hwh5w..`,
			31,
			29,
		],
		[
			map`
.2...h5.w.wh
w..ww.w6..wh
w..w2.h.....
.h.3.....hhw
4w....w.....
w..wh.......
...h.w4...2w
.w..w......6
..w...h.....
.h..2w.w43h.`,
			31,
			29,
		],
		[
			map`
..4653.h....
.4.w..wwh..3
w..w..2h....
6.......w.h.
ww....ww....
..ww.ww..h..
...h5w...h.w
.....h.4....
w.w.hw.h.w3.
h..hww...3..`,
			32,
			30,
		],
	],
];

const infoScreenMap = map`
YYYYYZYYZY
YYYYYYYYZZ
YYYYYYYYYY
YYYYYYYY07
XXXXXXXX98
XXXXXXXXWW
XXXXXXXXXW
XXXXXXXXXX`;

const chords = {
	Cmaj: {
		chord: tune`
2000: C5~2000 + C4~2000 + G4~2000 + E4~2000,
62000`,
		notes: ["C", "E", "G", "E", "D", "A"],
	},
	Em: {
		chord: tune`
1000: E5~1000 + G4~1000 + B4~1000,
31000`,
		notes: ["E", "G", "B", "G", "D", "A"],
	},
	Am: {
		chord: tune`
1000: E5~1000 + A4~1000 + C4~1000,
31000`,
		notes: ["A", "C", "E", "C", "D", "G"],
	},
	Fmaj7: {
		chord: tune`
1000: C5~1000 + A4~1000 + E5~1000 + F4~1000,
31000`,
		notes: ["A", "C", "F", "C", "D", "G"],
	},
	Dm: {
		chord: tune`
1000: D5~1000 + F5~1000 + A4~1000,
31000`,
		notes: ["D", "F", "A", "F", "E", "G"],
	},
	Gmaj: {
		chord: tune`
1000: G4~1000 + B4~1000 + D4~1000,
31000`,
		notes: ["G", "D", "B", "D", "E", "A"],
	},
	Bdim: {
		chord: tune`
1000: B4~1000 + D5~1000 + F4~1000,
31000`,
		notes: ["B", "D", "F", "D", "E", "G"],
	},
	AmOverE: {
		chord: tune`
1000: E4~1000 + A4~1000 + C5~1000,
31000`,
		notes: ["E", "A", "C", "A", "D", "G"],
	},
};

const notes = {
	Blank: tune`
16000`,
	A: tune`
500: A4~500,
15500`,
	B: tune`
500: B4~500,
15500`,
	C: tune`
500: C5~500,
15500`,
	D: tune`
500: D5~500,
15500`,
	E: tune`
500: E5~500,
15500`,
	F: tune`
500: F5~500,
15500`,
	G: tune`
500: G5~500,
15500`,
};

const chordProgression = [
	"Cmaj",
	"Em",
	"Am",
	"Fmaj7",
	"Dm",
	"Gmaj",
	"Bdim",
	"AmOverE",
];
let chordi = 0;
let notei = 0;

const playChord = (index = null) => {
	if (index === null) {
		if (chordi === chordProgression.length - 1) {
			chordi = 4;
		} else {
			chordi += 1;
		}
	} else {
		chordi = index;
	}

	notei = 0;

	playTune(chords[chordProgression[chordi]].chord);
};

const playNote = () => {
	const note = chords[chordProgression[chordi]].notes[notei];

	if (notei === chords[chordProgression[chordi]].notes.length - 1) {
		notei = 0;
	} else {
		notei += 1;
	}

	playTune(notes[note]);
};

const hasType = (x, y, type) => {
	let found = false;

	getTile(x, y).forEach((t) => {
		if (t.type === type) {
			found = true;
		}
	});

	return found;
};

const removeType = (x, y, type) => {
	getTile(x, y).forEach((t) => {
		if (t.type === type) {
			t.remove();
		}
	});
};

const hasOnlyType = (x, y, type) => {
	return hasType(x, y, type) && getTile(x, y).length == 1;
};

const selectableTiles = () =>
	selectableTypes.reduce((acc, v) => acc.concat(getAll(v)), []);
const cx = () => getFirst(cursor).x;
const cy = () => getFirst(cursor).y;

const moveCursor = (dx, dy) => {
	const sCols = selectableTiles()
		.map((s) => s.x)
		.sort((a, b) => a - b);
	const sRows = selectableTiles()
		.map((s) => s.y)
		.sort((a, b) => a - b);
	let nextCol = getFirst(cursor).x;
	let nextRow = getFirst(cursor).y;

	if (dy === 1) {
		nextRow = sRows.find((r) => r > getFirst(cursor).y);
	} else if (dy === -1) {
		nextRow = sRows.reverse().find((r) => r < getFirst(cursor).y);
	} else if (dx === 1) {
		nextCol = sCols.find((c) => c > getFirst(cursor).x);
	} else if (dx === -1) {
		nextCol = sCols.reverse().find((c) => c < getFirst(cursor).x);
	}

	getFirst(cursor).x = nextCol;
	getFirst(cursor).y = nextRow;
};

const updatePossibleMoves = () => {
	[valid, invalid].forEach((type) =>
		getAll(type).forEach((tile) => tile.remove())
	);

	if (selected) {
		potentialMoves(cx(), cy()).forEach((move) => {
			const check = checkMove(cx(), cy(), move.x, move.y);

			if (check.x !== null && check.y !== null) {
				addSprite(check.x, check.y, check.valid ? valid : invalid);
			}
		});
	}
};

const potentialMoves = (x, y) => {
	const n = numberAt(x, y);
	const undo = undoData(x, y);

	let moves = [
		{ x: x + n, y: y },
		{ x: x - n, y: y },
		{ x: x, y: y + n },
		{ x: x, y: y - n },
	];

	if (undo.valid) {
		if (undo.dirX == 1) {
			// remove the first element from moves
			moves = moves.slice(1);
		} else if (undo.dirX == -1) {
			// remove the second element from moves
			moves = moves.slice(0, 1).concat(moves.slice(2));
		} else if (undo.dirY == 1) {
			// remove the third element from moves
			moves = moves.slice(0, 2).concat(moves.slice(3));
		} else if (undo.dirY == -1) {
			// remove the fourth element from moves
			moves = moves.slice(0, 3);
		}

		moves.push({ x: undo.fromX, y: undo.fromY });
	}

	return moves;
};

const numberAt = (x, y) => {
	let number = null;

	numberTypes.forEach((type, i) => {
		if (hasType(x, y, type)) {
			number = i + 1;
		}
	});

	return number;
};

const ballCanLand = (x, y) => {
	return !unlandableTypes.some((t) => hasType(x, y, t));
};

const ballCanPass = (x, y) => {
	return !impassableTypes.some((t) => hasType(x, y, t));
};

const onMap = (x, y) => {
	return x >= 0 && x < width() && y >= 0 && y < height();
};

const checkMove = (x1, y1, x2, y2) => {
	const undo = undoData(x1, y1);

	if (undo.valid && undo.fromX == x2 && undo.fromY == y2) {
		return { x: x2, y: y2, valid: true, undo: true };
	} else {
	}

	// check the squares between x1, y1 and x2, y2
	const dx = x2 - x1;
	const dy = y2 - y1;
	const steps = Math.max(Math.abs(dx), Math.abs(dy));
	const xStep = dx / steps;
	const yStep = dy / steps;

	for (let i = 1; i < steps; i++) {
		const x = x1 + i * xStep;
		const y = y1 + i * yStep;

		if (!onMap(x, y)) {
			return { x: null, y: null, valid: false };
		} else if (!onMap(x + xStep, y + yStep)) {
			return { x: x, y: y, valid: false };
		} else if (!ballCanPass(x, y)) {
			return { x: x, y: y, valid: false };
		}
	}

	// check the destination tile
	if (!onMap(x2, y2)) {
		return { x: null, y: null, valid: false };
	} else if (steps == 1) {
		return { x: x2, y: y2, valid: hasType(x2, y2, hole) };
	} else {
		return { x: x2, y: y2, valid: ballCanLand(x2, y2) };
	}
};

const tryMoveFromCursor = (dx, dy) => {
	// select the first candidate move from potentialMoves that matches the direction of dx, dy
	const candidate = potentialMoves(cx(), cy()).find((move) => {
		return (
			(move.x < cx() && dx < 0) ||
			(move.x > cx() && dx > 0) ||
			(move.y < cy() && dy < 0) ||
			(move.y > cy() && dy > 0)
		);
	});

	if (candidate) {
		return tryMove(cx(), cy(), candidate.x, candidate.y);
	} else {
		return false;
	}
};

const tryMove = (x1, y1, x2, y2) => {
	const check = checkMove(x1, y1, x2, y2);

	if (check.valid) {
		currentCourse().strokes += 1;

		if (check.undo) {
			tryUndo(x1, y1);
			return;
		}

		getFirst(cursor).x = x2;
		getFirst(cursor).y = y2;

		const fromN = numberAt(x1, y1);

		removeType(x1, y1, numberTypes[fromN - 1]);

		if (hasType(x2, y2, hole)) {
			removeType(x2, y2, hole);
			addSprite(x2, y2, holeWon);
			holeVals[[x2, y2]] = fromN - 1;
			selected = false;
		} else {
			addSprite(x2, y2, numberTypes[fromN - 2]);
		}

		addArrows(x1, y1, x2, y2);
		updatePossibleMoves();

		if (getAll(hole).length === 0) {
			playChord(0);
		} else if (!selected) {
			playChord();
		} else {
			playNote();
		}
	}
};

const getRandomInt = (max) => {
	return Math.floor(Math.random() * max);
};

const undoData = (x, y) => {
	const inArrow = inArrowTypes.find((t) => hasType(x, y, t));
	const outArrow = outArrowTypes.find((t) => hasType(x, y, t));
	const fromN = (numberAt(x, y) || holeVals[[x, y]]) + 1;

	if (fromN && inArrow && !outArrow) {
		const dirX = inArrow === leftIn ? -1 : inArrow === rightIn ? 1 : 0;
		const dirY = inArrow === upIn ? -1 : inArrow === downIn ? 1 : 0;
		const deltaX = dirX * fromN;
		const deltaY = dirY * fromN;
		const fromX = x + deltaX;
		const fromY = y + deltaY;

		return {
			valid: true,
			fromN,
			dirX,
			dirY,
			deltaX,
			deltaY,
			fromX,
			fromY,
		};
	} else {
		return { valid: false };
	}
};

const tryUndo = (x, y) => {
	const undo = undoData(x, y);

	if (undo.valid) {
		let steps = Math.max(Math.abs(undo.deltaX), Math.abs(undo.deltaY));
		let xStep = undo.deltaX / steps;
		let yStep = undo.deltaY / steps;

		for (let i = 0; i < steps + 1; i++) {
			const sx = x + i * xStep;
			const sy = y + i * yStep;

			outArrowTypes.forEach((t) => removeType(sx, sy, t));

			if (!(sx === undo.fromX && sy === undo.fromY)) {
				inArrowTypes.forEach((t) => removeType(sx, sy, t));
			}
		}

		if (numberAt(x, y)) {
			removeType(x, y, numberTypes[numberAt(x, y) - 1]);
		}

		if (hasType(x, y, holeWon)) {
			removeType(x, y, holeWon);
			addSprite(x, y, hole);
		}

		addSprite(undo.fromX, undo.fromY, numberTypes[undo.fromN - 1]);

		selected = true;

		getFirst(cursor).x = undo.fromX;
		getFirst(cursor).y = undo.fromY;
	} else {
		selected = false;
	}

	updatePossibleMoves();
};

const addArrows = (x1, y1, x2, y2) => {
	const dx = x2 - x1;
	const dy = y2 - y1;
	const steps = Math.max(Math.abs(dx), Math.abs(dy));
	const xStep = dx / steps;
	const yStep = dy / steps;

	const inArrow =
		xStep === 0
			? yStep > 0
				? upIn
				: downIn
			: xStep > 0
			? leftIn
			: rightIn;

	const outArrow =
		xStep === 0
			? yStep > 0
			? downOut
			: upOut
			: xStep > 0
			? rightOut
			: leftOut;

	addSprite(x1, y1, outArrow);
	addSprite(x2, y2, inArrow);

	for (let i = 1; i < steps; i++) {
		const x = x1 + i * xStep;
		const y = y1 + i * yStep;

		addSprite(x, y, outArrow);
		addSprite(x, y, inArrow);
	}
};

const loadCourses = () => {
	loadedCourses = [];

	if (gameSelect === 3) {
		const allCourses = courseGroups.flat();
		const shuffledCourses = allCourses.sort(() => Math.random() - 0.5);

		shuffledCourses.forEach((course, i) => {
			loadedCourses.push({
				map: course[0],
				par: course[1],
				best: course[2],
				strokes: 0,
				number: i + 1,
				seconds: 0,
				startTime: null,
			});
		});
	} else {
		let starti = 0;
		let endi = 17;

		if (gameSelect === 1) {
			endi = 8;
		} else if (gameSelect === 2) {
			starti = 9;
		}

		for (let i = starti; i < endi + 1; i++) {
			const group = courseGroups[i];
			const course = group[getRandomInt(group.length)];

			loadedCourses.push({
				map: course[0],
				par: course[1],
				best: course[2],
				strokes: 0,
				number: i + 1,
				seconds: 0,
				startTime: null,
			});
		}
	}
};

const setCourseNumber = (n) => {
	courseNumber = n;
	holeVals = {};
};

const currentCourse = () => {
	return loadedCourses[courseNumber];
};

const moreCourses = () => {
	return courseNumber < loadedCourses.length - 1;
};

const drawGameTitle = () => {
	screen = "gameTitle";

	clearText();
	setMap(infoScreenMap);

	addText("countdown golf", { x: 1, y: 4, color: color`0` });
	addText(`< ${gameSelectOptions[gameSelect]} >`, {
		x: 1,
		y: 6,
		color: color`0`,
	});

	if (wonOnce) {
		addText("game", { x: 1, y: 9, color: color`2` });
		addText("by", { x: 1, y: 11, color: color`2` });
		addText("schoblaska", { x: 1, y: 13, color: color`2` });
	} else {
		addText("wasd: move", { x: 1, y: 9, color: color`2` });
		addText("j: select", { x: 1, y: 10, color: color`2` });
		addText("based on", { x: 1, y: 12, color: color`2` });
		addText("herugolf", { x: 1, y: 13, color: color`2` });
		addText("by nikoli", { x: 1, y: 14, color: color`2` });
	}
};

const drawCourseTitle = () => {
	screen = "courseTitle";

	clearText();
	setMap(infoScreenMap);

	addText("course #" + currentCourse().number, {
		x: 1,
		y: 4,
		color: color`0`,
	});
	addText("par " + currentCourse().par, {
		x: 1,
		y: 6,
		color: color`0`,
	});

	if (courseNumber === 0) {
		addText("good luck!", { x: 1, y: 9, color: color`2` });
	} else {
		drawScore();
	}
};

const drawVictory = () => {
	screen = "victory";
	wonOnce = true;

	clearText();
	setMap(infoScreenMap);

	const totStrokes = loadedCourses.reduce((acc, c) => acc + c.strokes, 0);
	const totPar = loadedCourses.reduce((acc, c) => acc + c.par, 0);
	const totBest = loadedCourses.reduce((acc, c) => acc + c.best, 0);

	if (totStrokes === totBest) {
		addText("wow!", { x: 1, y: 3, color: color`0` });
	}

	if (totStrokes <= totPar) {
		addText("nice shooting!", { x: 1, y: 4, color: color`0` });
	}

	addText("you win!", { x: 1, y: 6, color: color`0` });

	drawScore();
};

const drawScore = () => {
	const prevStrokes = loadedCourses[courseNumber - 1].strokes;
	const prevPar = loadedCourses[courseNumber - 1].par;
	const prevNum = loadedCourses[courseNumber - 1].number;
	const prevSec = loadedCourses[courseNumber - 1].seconds;

	addText(`course #${prevNum}:`, {
		x: 1,
		y: 9,
		color: color`2`,
	});
	addText(
		` ${prevStrokes} (${parScore(prevStrokes, prevPar)}) ${formatSeconds(
			prevSec
		)}`,
		{ x: 1, y: 10, color: color`2` }
	);

	const strokesSoFar = loadedCourses.reduce((acc, c) => acc + c.strokes, 0);
	const parSoFar = loadedCourses
		.slice(0, courseNumber)
		.reduce((acc, c) => acc + c.par, 0);
	const bestSoFar = loadedCourses
		.slice(0, courseNumber)
		.reduce((acc, c) => acc + c.best, 0);
	const secondsSoFar = loadedCourses.reduce((acc, c) => acc + c.seconds, 0);

	const bigScore = secondsSoFar > 60 * 60 || strokesSoFar > 500;
	const flawless = strokesSoFar === bestSoFar;

	if (bigScore && flawless) {
		addText(`${gameSelectOptions[gameSelect]}:`, {
			x: 1,
			y: 11,
			color: color`2`,
		});
		addText(` ${strokesSoFar} (${parScore(strokesSoFar, parSoFar)})`, {
			x: 1,
			y: 12,
			color: color`2`,
		});
		addText(` ${formatSeconds(secondsSoFar)}`, {
			x: 1,
			y: 13,
			color: color`2`,
		});
		addText(" flawless!", { x: 1, y: 14, color: color`2` });
	} else if (bigScore) {
		addText(`${gameSelectOptions[gameSelect]}:`, {
			x: 1,
			y: 12,
			color: color`2`,
		});
		addText(` ${strokesSoFar} (${parScore(strokesSoFar, parSoFar)})`, {
			x: 1,
			y: 13,
			color: color`2`,
		});
		addText(` ${formatSeconds(secondsSoFar)}`, {
			x: 1,
			y: 14,
			color: color`2`,
		});
	} else {
		addText(`${gameSelectOptions[gameSelect]}:`, {
			x: 1,
			y: 12,
			color: color`2`,
		});
		addText(
			` ${strokesSoFar} (${parScore(
				strokesSoFar,
				parSoFar
			)}) ${formatSeconds(secondsSoFar)}`,
			{
				x: 1,
				y: 13,
				color: color`2`,
			}
		);
		if (flawless) {
			addText(" flawless!", { x: 1, y: 14, color: color`2` });
		}
	}
};

const parScore = (strokes, par) => {
	if (par === strokes) {
		return "E";
	} else if (par > strokes) {
		return "-" + (par - strokes);
	} else {
		return "+" + (strokes - par);
	}
};

const formatSeconds = (seconds) => {
	const hours = Math.floor(seconds / 3600);
	const minutes = Math.floor((seconds % 3600) / 60);
	const paddedMinutes = minutes.toString().padStart(2, "0");
	const secs = Math.floor(seconds % 60);
	const paddedSecs = secs.toString().padStart(2, "0");

	if (hours > 0) {
		return `${hours}:${paddedMinutes}:${paddedSecs}`;
	} else {
		return `${minutes}:${paddedSecs}`;
	}
};

const drawCourse = () => {
	screen = "course";

	clearText();
	setMap(currentCourse().map);
	currentCourse().startTime = new Date();

	for (let x = 0; x < width(); x++) {
		for (let y = 0; y < height(); y++) {
			if (!hasType(x, y, water)) {
				addSprite(x, y, grass);
			}
		}
	}

	const initCursor = selectableTiles()[0];
	addSprite(initCursor.x, initCursor.y, cursor);
};

const handleInput = (btn) => {
	const inputHandlers = {
		gameTitle: gameTitleInput,
		courseTitle: courseTitleInput,
		course: courseInput,
		victory: victoryInput,
	};

	inputHandlers[screen](btn);
};

const gameTitleInput = (btn) => {
	if (btn === "a") {
		gameSelect -= 1;

		if (gameSelect < 0) {
			gameSelect = gameSelectOptions.length - 1;
		}

		drawGameTitle();
	} else if (btn === "d") {
		gameSelect += 1;

		if (gameSelect > gameSelectOptions.length - 1) {
			gameSelect = 0;
		}

		drawGameTitle();
	} else if (btn === "j") {
		loadCourses();
		setCourseNumber(0);
		drawCourseTitle();
	}
};

const courseTitleInput = (btn) => {
	drawCourse();
};

const victoryInput = (btn) => {
	drawGameTitle();
};

const courseInput = (btn) => {
	if (btn === "w") {
		if (selected) {
			tryMoveFromCursor(0, -1);
		} else {
			moveCursor(0, -1);
		}
	} else if (btn === "a") {
		if (selected) {
			tryMoveFromCursor(-1, 0);
		} else {
			moveCursor(-1, 0);
		}
	} else if (btn === "s") {
		if (selected) {
			tryMoveFromCursor(0, 1);
		} else {
			moveCursor(0, 1);
		}
	} else if (btn === "d") {
		if (selected) {
			tryMoveFromCursor(1, 0);
		} else {
			moveCursor(1, 0);
		}
	} else if (btn === "j") {
		const selectable = selectableTypes.some((t) => hasType(cx(), cy(), t));

		if (selectable) {
			selected = !selected;

			if (selected) {
				playNote();
			}

			updatePossibleMoves();
		}
	} else if (btn === "k") {
		selected = false;
		updatePossibleMoves();
	}
};

drawGameTitle();

onInput("w", () => handleInput("w"));
onInput("a", () => handleInput("a"));
onInput("s", () => handleInput("s"));
onInput("d", () => handleInput("d"));
onInput("j", () => handleInput("j"));
onInput("k", () => handleInput("k"));

afterInput(() => {
	if (screen === "course" && getAll(hole).length == 0) {
		const endTime = new Date();

		currentCourse().seconds = (endTime - currentCourse().startTime) / 1000;

		if (moreCourses()) {
			setCourseNumber(courseNumber + 1);
			drawCourseTitle();
		} else {
			setCourseNumber(courseNumber + 1);
			drawVictory();
		}
	}
});
